<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消息推送记录列表</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card content-wrap">
        <!--查询-->
        <!--<div class="layui-form layui-card-header layuiadmin-card-header-auto">-->
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm3">
                        <label class="layui-form-label">消息内容</label>
                        <div class="layui-input-block">
                            <input type="text" id="mrContent" placeholder="请输入消息内容" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-sm3">
                        <label class="layui-form-label">推送方式</label>
                        <div class="layui-input-block">
                            <select id="pushType">
                                <option value="">全部</option>
                                <option value="app">APP</option>
                                <option value="wx_public">微信公众号</option>
                                <option value="wx_applet">微信小程序</option>
                                <!--<option value="sms">短信</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-sm3">
                        <label class="layui-form-label">发送状态</label>
                        <div class="layui-input-block">
                            <select id="pushStatus">
                                <option value="">全部</option>
                                <option value="push_no">未发送</option>
                                <option value="push_yes">已发送</option>
                                <option value="push_stop">暂停发送</option>
                                <!--<option value="sms">短信</option>-->
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10">
                    <!--<div class="layui-col-sm3">-->
                    <!--<label class="layui-form-label">时间类型</label>-->
                    <!--<div class="layui-input-block">-->
                    <!--<select id="timeType">-->
                    <!--<option value="dsc_sign">创建时间</option>-->
                    <!--<option value="dsc_start">修改时间</option>-->
                    <!--</select>-->
                    <!--</div>-->
                    <!--</div>-->
                    <div class="layui-col-sm3">
                        <label class="layui-form-label">发送开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="fromTime" placeholder="发送开始时间" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm3">
                        <label class="layui-form-label">发送结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="toTime" placeholder="发送结束时间" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm6">
                        <a id="doSearch" class="layui-btn add_btn"><i class="layui-icon layui-icon-search"></i>搜索</a>
                        <button type="reset" class="layui-btn delete_btn"><i class="layui-icon layui-icon-delete"></i>清空</button>
                        <a id="delRecord" class="layui-btn delete_btn"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    </div>
                </div>
            </div>
        </form>


        <!--数据列表展示-->
        <div>
        <!--<script type="text/html" id="optToolbar">-->
            <!--<div>-->
                <!--<button class="layui-btn layuiadmin-btn-useradmin delete_btn ax-btn" lay-event="delRecord"><i class="layui-icon layui-icon-delete"></i>删除</button>-->
            <!--</div>-->
        <!--</script>-->

        <table class="layui-hide" id="dataListTable"
               lay-filter="active"></table>
    </div>


    </div>
</div>


</body>

<script>

    var table;
    var tableObj;

    layui.use(['table','form','layer','laydate'], function() {
        table = layui.table;
        var form = layui.form,
            layDateFrom = layui.laydate,
            layDateTo = layui.laydate,
            layer=layui.layer;

        // 初始化日期控件
        var fromTime = layDateFrom.render({
            elem: '#fromTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    toTime.config.min={
                        year:date.year,
                        month:date.month-1,//关键
                        date:date.date,
                        hours:date.hours,
                        minutes:date.minutes,
                        seconds:date.seconds
                    };
                }
            }
        });
        var toTime = layDateTo.render({
            elem: '#toTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    fromTime.config.max={
                        year:date.year,
                        month:date.month-1,//关键
                        date:date.date,
                        hours:date.hours,
                        minutes:date.minutes,
                        seconds:date.seconds
                    };
                }
            }
        });

        tableObj = ax.VTable({
            id: 'loadDataList',
            elem : '#dataListTable',
            autoPrefix: false,
            url :schoolWebUrl + '/api/message/record/list',
            // toolbar: '#optToolbar',
            title:'消息记录列表',
            cols : [ [
                {type : 'checkbox', fixed : 'left'},
                {type: 'numbers', width : 80, title : '序号', fixed : 'left'},
                {field : 'mrSenderName', width : 100, title : '推送人', fixed : 'left' },
                {field : 'pushTypeName', width : 150, title : '推送状态'},
                {field : 'pushStatusName', width : 150, title : '推送状态'},
                {field : 'mrContent', minWidth : 250, title : '推送内容' },
                {field : 'mrRecipient', width : 150, title : '接收人' },
                {field : 'mrRecipientAccount', width : 180, title : '接收人账号' },
                {field : 'submitTime', width : 180, title : '提交时间' },
                {field : 'pushTime', width : 180, title : '推送时间' }
            ] ]

        });

        var $ = layui.$;

        $('#doSearch').on('click', function(){
            searchData();
        });

        $("#delRecord").on("click", function () {
            var checkStatus = table.checkStatus(tableObj.config.id);
            var data = checkStatus.data;
            if(data.length<=0) {
                top.layer.open({
                    title: '信息提示'
                    ,content: '请选择删除的数据！'
                });
            } else {
                top.layer.confirm('确定需要删除选中的记录！', function (index) {
                    top.layer.closeAll('dialog');
                    var ids = [];
                    for (var i = 0; i < data.length; i++) {
                        ids.push(data[i].id);
                    }
                    delRecord(ids.join(","));
                });
            }
        });

        //头工具栏事件
        // table.on('toolbar()', function(obj){
        //     var checkStatus = table.checkStatus(obj.config.id);
        //     switch(obj.event){
        //         case 'delRecord':
        //             var data = checkStatus.data;
        //             if(data.length<=0) {
        //                 top.layer.open({
        //                     title: '信息提示'
        //                     ,content: '请选择删除的数据！'
        //                 });
        //                 break;
        //             }
        //             top.layer.confirm('确定需要删除选中的记录！', function (index) {
        //                 top.layer.closeAll('dialog');
        //                 var ids = [];
        //                 for (var i = 0; i < data.length; i++) {
        //                     ids.push(data[i].id);
        //                 }
        //                 delRecord(ids.join(","));
        //             })
        //             break;
        //     };
        // });

    });

    function searchData() {
        //执行重载
        tableObj.reload({
            page : {
                curr: 1 //重新从第 1 页开始
            },
            where : {
                mrContent : $('#mrContent').val(),
                pushType : $('#pushType').val(),
                pushStatus : $('#pushStatus').val(),
                fromTime : $('#fromTime').val(),
                toTime : $('#toTime').val()
            }
        });
    }

    //删除消息记录
    function delRecord(ids) {
        var data={ids:ids};
        ax.get({
            autoPrefix: false,
            url :schoolWebUrl + '/api/message/record/delete',
            data:data,
            success:function (res) {
                if(res.code == 0) {
                    top.layer.msg("删除成功");
                    searchData();
                } else {
                    top.layer.msg(res.msg);
                }
            },
            error : function(request) {
                top.layer.msg("系统错误，联系管理员");
            }
        });
    }
</script>
</html>